#include <iostream>
using namespace std;

template <typename T>
class arrayStack
{
public:
    arrayStack(int size);
    ~arrayStack();
public:
    bool isEmpty();
    bool isFull();
    int getCount();
    int getSize();
    T top();
    T pop();
    bool push(T data);
    
private:
    T *data;
    int ptop;
    int count;
    int size;
};

template <typename T>
arrayStack<T>::arrayStack(int size)
{
    data = new T[size];
	memset(data, 0, sizeof(T)*size);
    ptop = size;
    count = 0;
    this->size = size;
}

template <typename T>
arrayStack<T>::~arrayStack()
{
    delete data;
    data = NULL;
}

template <typename T>
bool arrayStack<T>::isEmpty()
{
    return count == 0;
}

template <typename T>
bool arrayStack<T>::isFull()
{
    return count == size;
}

template <typename T>
int arrayStack<T>::getCount()
{
    return count;
}

template <typename T>
int arrayStack<T>::getSize()
{
    return size;
}

template <typename T>
T arrayStack<T>::top()
{
    return data[ptop];
}

template <typename T>
T arrayStack<T>::pop()
{
    if (isEmpty())
        return (T)-1;
    T d = data[ptop++];
    count--;
    return d;
}

template <typename T>
bool arrayStack<T>::push(T d)
{
    if (isFull())
        return false;
    data[--ptop] = d;
    count++;
    return true;
}

int main() {
    
    arrayStack<int> stack(10);
    for(int i=0; i<10; i++)
        stack.push(i);
    cout<<"stack count:"<<stack.getCount()<<endl;
    for(int i=0; i<10; i++)
        cout<< "stack item:"<<stack.pop()<<endl;
	
    system("pause");
    return 0;
}